# trace generated using paraview version 5.9.1
import os
cur_path = os.getcwd()
# os.chdir('/public/home/gfwang/software/ParaView-4.4.0-Qt4-Linux-64bit/')
#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

os.chdir(cur_path)
folder = 'F:\\QCH_ignition_model\\python\\55mm_25mm_\\'
simu_num = 4
simu_iter = 200
iter_gap = 5

# create a new 'CSV Reader'
shell_points_halfcsv = CSVReader(registrationName='shell_points_half.csv', FileName=['F:\\QCH_ignition_model\\python\\data\\shell_points_half.csv'])

# Create a new 'SpreadSheet View'
spreadSheetView1 = CreateView('SpreadSheetView')
spreadSheetView1.ColumnToSort = ''
spreadSheetView1.BlockSize = 1024

# show data in view
shell_points_halfcsvDisplay = Show(shell_points_halfcsv, spreadSheetView1, 'SpreadSheetRepresentation')

# get layout
layout1 = GetLayoutByName("Layout #1")

# add view to a layout so it's visible in UI
AssignViewToLayout(view=spreadSheetView1, layout=layout1, hint=0)

# find view
renderView1 = FindViewOrCreate('RenderView1', viewtype='RenderView')

# update the view to ensure updated data information
renderView1.Update()

# create a new 'Table To Points'
tableToPoints1 = TableToPoints(registrationName='TableToPoints1', Input=shell_points_halfcsv)
tableToPoints1.XColumn = 'x'
tableToPoints1.YColumn = 'x'
tableToPoints1.ZColumn = 'x'

# Properties modified on tableToPoints1
tableToPoints1.YColumn = 'y'
tableToPoints1.ZColumn = 'z'

# show data in view
tableToPoints1Display = Show(tableToPoints1, spreadSheetView1, 'SpreadSheetRepresentation')

# hide data in view
Hide(shell_points_halfcsv, spreadSheetView1)

# update the view to ensure updated data information
spreadSheetView1.Update()

# create a new 'Glyph'
glyph1 = Glyph(registrationName='Glyph1', Input=tableToPoints1,
    GlyphType='Arrow')
glyph1.OrientationArray = ['POINTS', 'No orientation array']
glyph1.ScaleArray = ['POINTS', 'No scale array']
glyph1.ScaleFactor = 0.0108
glyph1.GlyphTransform = 'Transform2'

# Properties modified on glyph1
glyph1.GlyphType = 'Box'
glyph1.ScaleFactor = 0.004104
glyph1.MaximumNumberOfSamplePoints = 100000

# show data in view
glyph1Display = Show(glyph1, spreadSheetView1, 'SpreadSheetRepresentation')

# update the view to ensure updated data information
spreadSheetView1.Update()

# hide data in view
Hide(glyph1, spreadSheetView1)

# set active source
SetActiveSource(glyph1)

# show data in view
glyph1Display = Show(glyph1, spreadSheetView1, 'SpreadSheetRepresentation')

# show data in view
glyph1Display = Show(glyph1, spreadSheetView1, 'SpreadSheetRepresentation')

# destroy spreadSheetView1
Delete(spreadSheetView1)
del spreadSheetView1

# close an empty frame
layout1.Collapse(2)

# set active view
SetActiveView(renderView1)

# show data in view
glyph1Display = Show(glyph1, renderView1, 'GeometryRepresentation')

# trace defaults for the display properties.
glyph1Display.Representation = 'Surface'
glyph1Display.ColorArrayName = [None, '']
glyph1Display.SelectTCoordArray = 'None'
glyph1Display.SelectNormalArray = 'Normals'
glyph1Display.SelectTangentArray = 'None'
glyph1Display.OSPRayScaleArray = 'Normals'
glyph1Display.OSPRayScaleFunction = 'PiecewiseFunction'
glyph1Display.SelectOrientationVectors = 'None'
glyph1Display.ScaleFactor = 0.011210399866104127
glyph1Display.SelectScaleArray = 'None'
glyph1Display.GlyphType = 'Arrow'
glyph1Display.GlyphTableIndexArray = 'None'
glyph1Display.GaussianRadius = 0.0005605199933052063
glyph1Display.SetScaleArray = ['POINTS', 'Normals']
glyph1Display.ScaleTransferFunction = 'PiecewiseFunction'
glyph1Display.OpacityArray = ['POINTS', 'Normals']
glyph1Display.OpacityTransferFunction = 'PiecewiseFunction'
glyph1Display.DataAxesGrid = 'GridAxesRepresentation'
glyph1Display.PolarAxes = 'PolarAxesRepresentation'

# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
glyph1Display.ScaleTransferFunction.Points = [-1.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]

# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
glyph1Display.OpacityTransferFunction.Points = [-1.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]

# reset view to fit data
renderView1.ResetCamera()

# reset view to fit data
renderView1.ResetCamera()

# reset view to fit data
renderView1.ResetCamera()

# Properties modified on glyph1
glyph1.ScaleFactor = 0.0030240000000000006

# update the view to ensure updated data information
renderView1.Update()

# Properties modified on glyph1
glyph1.MaximumNumberOfSamplePoints = 500000

# update the view to ensure updated data information
renderView1.Update()


'''The loop'''
for jj in range(0,simu_num,1):
    foldername = folder + str(jj).zfill(5) + '\\'
    for ii in range(0,simu_iter,iter_gap):
        filename = str(ii).zfill(5)
        
        # create a new 'CSV Reader'
        a00075csv = CSVReader(registrationName='00075.csv', FileName=[foldername + filename + '.csv'])

        # Create a new 'SpreadSheet View'
        spreadSheetView1 = CreateView('SpreadSheetView')
        spreadSheetView1.ColumnToSort = ''
        spreadSheetView1.BlockSize = 1024
        
        # show data in view
        a00075csvDisplay = Show(a00075csv, spreadSheetView1, 'SpreadSheetRepresentation')
        
        # add view to a layout so it's visible in UI
        AssignViewToLayout(view=spreadSheetView1, layout=layout1, hint=0)
        
        # update the view to ensure updated data information
        renderView1.Update()
        
        # create a new 'Table To Points'
        tableToPoints2 = TableToPoints(registrationName='TableToPoints2', Input=a00075csv)
        tableToPoints2.XColumn = 'k'
        tableToPoints2.YColumn = 'k'
        tableToPoints2.ZColumn = 'k'
        
        # Properties modified on tableToPoints2
        tableToPoints2.XColumn = 'x'
        tableToPoints2.YColumn = 'y'
        tableToPoints2.ZColumn = 'z'
        
        # show data in view
        tableToPoints2Display = Show(tableToPoints2, spreadSheetView1, 'SpreadSheetRepresentation')
        
        # hide data in view
        Hide(a00075csv, spreadSheetView1)
        
        # update the view to ensure updated data information
        spreadSheetView1.Update()
        
        # create a new 'Glyph'
        glyph2 = Glyph(registrationName='Glyph2', Input=tableToPoints2,
            GlyphType='Arrow')
        glyph2.OrientationArray = ['POINTS', 'No orientation array']
        glyph2.ScaleArray = ['POINTS', 'No scale array']
        glyph2.ScaleFactor = 0.0064
        glyph2.GlyphTransform = 'Transform2'
        
        # Properties modified on glyph2
        glyph2.GlyphType = 'Sphere'
        glyph2.ScaleFactor = 0.00128
        
        # show data in view
        glyph2Display = Show(glyph2, spreadSheetView1, 'SpreadSheetRepresentation')
        
        # update the view to ensure updated data information
        spreadSheetView1.Update()
        
        # destroy spreadSheetView1
        Delete(spreadSheetView1)
        del spreadSheetView1
        
        # close an empty frame
        layout1.Collapse(2)
        
        # set active view
        SetActiveView(renderView1)
        
        # set active source
        SetActiveSource(glyph2)
        
        # show data in view
        glyph2Display = Show(glyph2, renderView1, 'GeometryRepresentation')
        
        # trace defaults for the display properties.
        glyph2Display.Representation = 'Surface'
        glyph2Display.ColorArrayName = [None, '']
        glyph2Display.SelectTCoordArray = 'None'
        glyph2Display.SelectNormalArray = 'Normals'
        glyph2Display.SelectTangentArray = 'None'
        glyph2Display.OSPRayScaleArray = 'Normals'
        glyph2Display.OSPRayScaleFunction = 'PiecewiseFunction'
        glyph2Display.SelectOrientationVectors = 'None'
        glyph2Display.ScaleFactor = 0.0064247908070683485
        glyph2Display.SelectScaleArray = 'None'
        glyph2Display.GlyphType = 'Arrow'
        glyph2Display.GlyphTableIndexArray = 'None'
        glyph2Display.GaussianRadius = 0.0003212395403534174
        glyph2Display.SetScaleArray = ['POINTS', 'Normals']
        glyph2Display.ScaleTransferFunction = 'PiecewiseFunction'
        glyph2Display.OpacityArray = ['POINTS', 'Normals']
        glyph2Display.OpacityTransferFunction = 'PiecewiseFunction'
        glyph2Display.DataAxesGrid = 'GridAxesRepresentation'
        glyph2Display.PolarAxes = 'PolarAxesRepresentation'
        
        # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
        glyph2Display.ScaleTransferFunction.Points = [-0.9749279618263245, 0.0, 0.5, 0.0, 0.9749279618263245, 1.0, 0.5, 0.0]
        
        # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
        glyph2Display.OpacityTransferFunction.Points = [-0.9749279618263245, 0.0, 0.5, 0.0, 0.9749279618263245, 1.0, 0.5, 0.0]
        
        # change solid color
        glyph2Display.AmbientColor = [1.0, 0.0, 0.0]
        glyph2Display.DiffuseColor = [1.0, 0.0, 0.0]
        
        # Properties modified on glyph2
        glyph2.ScaleFactor = 0.0020480000000000003
        
        # update the view to ensure updated data information
        renderView1.Update()
        
        # Properties modified on glyph2
        glyph2.ScaleFactor = 0.0034560000000000003
        
        # update the view to ensure updated data information
        renderView1.Update()
        
        # layout/tab size in pixels
        layout1.SetSize(1343, 749)
        
        # current camera placement for renderView1
        renderView1.CameraPosition = [0.29514001011578533, 0.0, 0.133494534234166]
        renderView1.CameraFocalPoint = [-0.008379493571044203, 0.0, 0.023022469372909103]
        renderView1.CameraViewUp = [-0.34202014332566893, 0.0, 0.9396926207859083]
        renderView1.CameraParallelScale = 0.08359821751980526
        
        # save screenshot
        SaveScreenshot(foldername+filename+'.bmp', renderView1, ImageResolution=[1343, 739])
        '''!!!!!!!!!!delete'''
        # destroy glyph2
        Delete(glyph2)
        del glyph2
        
        # set active source
        SetActiveSource(a00075csv)
        
        # destroy tableToPoints2
        Delete(tableToPoints2)
        del tableToPoints2
        
        # destroy a00000csv
        Delete(a00075csv)
        del a00075csv

#================================================================
# addendum: following script captures some of the application
# state to faithfully reproduce the visualization during playback
#================================================================

#--------------------------------
# saving layout sizes for layouts

# layout/tab size in pixels
layout1.SetSize(1343, 749)

#-----------------------------------
# saving camera placements for views

# current camera placement for renderView1
renderView1.CameraPosition = [0.29514001011578533, 0.0, 0.133494534234166]
renderView1.CameraFocalPoint = [-0.008379493571044203, 0.0, 0.023022469372909103]
renderView1.CameraViewUp = [-0.34202014332566893, 0.0, 0.9396926207859083]
renderView1.CameraParallelScale = 0.08359821751980526

#--------------------------------------------
# uncomment the following to render all views
# RenderAllViews()
# alternatively, if you want to write images, you can use SaveScreenshot(...).